package com.bear.atlassianmcp.jira.model.request;

import java.util.HashMap;
import java.util.Map;

/**
 * 创建Issue请求模型
 * 用于构建Jira创建Issue的请求体
 */
public class CreateIssueRequest {

    private Map<String, Object> fields;

    public CreateIssueRequest() {
        this.fields = new HashMap<>();
    }

    /**
     * 设置项目
     */
    public CreateIssueRequest project(String projectKey) {
        Map<String, Object> project = new HashMap<>();
        project.put("key", projectKey);
        fields.put("project", project);
        return this;
    }

    /**
     * 设置标题
     */
    public CreateIssueRequest summary(String summary) {
        fields.put("summary", summary);
        return this;
    }

    /**
     * 设置描述
     */
    public CreateIssueRequest description(String description) {
        fields.put("description", description);
        return this;
    }

    /**
     * 设置Issue类型
     */
    public CreateIssueRequest issueType(String issueTypeName) {
        Map<String, Object> issueType = new HashMap<>();
        issueType.put("name", issueTypeName);
        fields.put("issuetype", issueType);
        return this;
    }

    /**
     * 设置优先级
     */
    public CreateIssueRequest priority(String priorityName) {
        Map<String, Object> priority = new HashMap<>();
        priority.put("name", priorityName);
        fields.put("priority", priority);
        return this;
    }

    /**
     * 设置经办人
     */
    public CreateIssueRequest assignee(String assigneeName) {
        Map<String, Object> assignee = new HashMap<>();
        assignee.put("name", assigneeName);
        fields.put("assignee", assignee);
        return this;
    }

    /**
     * 设置自定义字段
     */
    public CreateIssueRequest customField(String fieldId, Object value) {
        fields.put(fieldId, value);
        return this;
    }

    /**
     * 构建最终的请求体
     */
    public Map<String, Object> build() {
        Map<String, Object> request = new HashMap<>();
        request.put("fields", fields);
        return request;
    }

    // Getters and Setters
    public Map<String, Object> getFields() {
        return fields;
    }

    public void setFields(Map<String, Object> fields) {
        this.fields = fields;
    }
}
